package fengstyle.order;

import fengstyle.feign.StockFeign;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class OrderService {

    @Resource
    private OrderMapper mapper;

    @Autowired
    private StockFeign feign;

    @GlobalTransactional
    public void addOrder(Order order) {
        mapper.insert(order);
        feign.addStock(order.getId(), order.getNo(), order.getUserName());
    }

    @GlobalTransactional
    public void addOrderException(Order order) {
        mapper.insert(order);
        feign.addStockException(order.getId(), order.getNo(), order.getUserName());
    }
}
